/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { connect } from 'dva';
import { Form, Input, Select } from 'antd';

const FormItem = Form.Item;
const { Option } = Select;

const formItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 8 },
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 12 },
  },
};

const AddOutlets = ({ form, allocation }) => {
  const { getFieldDecorator } = form;
  const { oneOption, type } = allocation;
  return (
    <Form>
      <FormItem {...formItemLayout} label="快递品牌">
        {type == 'add' ? (
          getFieldDecorator('brand', {
            initialValue: type == 'correct' ? oneOption.brand : 'zt',
            rules: [{ required: true, message: '快递品牌不能为空!' }],
          })(
            <Select
              showSearch
              optionFilterProp="children"
              filterOption={(input, option) =>
                option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
              }
            >
              <Option value="zt">中通快递</Option>
              <Option value="sto">申通快递</Option>
              <Option value="yt">圆通速递</Option>
              <Option value="yd">韵达快递</Option>
              <Option value="jt">极兔速递</Option>
              <Option value="ems">邮政速递</Option>
            </Select>,
          )
        ) : (
          <div name="brand">{oneOption.brand}</div>
        )}
      </FormItem>
      <FormItem {...formItemLayout} label="网点编号">
        {getFieldDecorator('branch_code', {
          initialValue: type == 'correct' ? oneOption.branch_code : '',
          rules: [{ required: true, message: '网点编号不能为空!' }],
        })(<Input disabled={type !== 'add'} placeholder="请输入快递公司网点编号" />)}
      </FormItem>
      <FormItem {...formItemLayout} label="网点名称">
        {getFieldDecorator('branch_name', {
          initialValue: type == 'correct' ? oneOption.branch_name : '',
          rules: [{ required: true, message: '网点名称不能为空!' }],
        })(<Input placeholder="请输入快递公司网点名称" />)}
      </FormItem>
    </Form>
  );
};

export default connect(({ allocation }) => ({ allocation }))(AddOutlets);
